package com.bluefoxyu.controller;

import com.bluefoxyu.domain.entity.Course;
import com.bluefoxyu.domain.result.Result;
import com.bluefoxyu.domain.vo.CourseVO;
import com.bluefoxyu.service.ICourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 课程信息表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/course")
@RequiredArgsConstructor
@Tag(name ="管理页面课程接口")
public class CourseController {

    private final ICourseService courseService;

    @Operation(summary = "添加教师所授课程")
    @PutMapping("/addCourse")
    public Result<String> addCourse(@RequestBody Course course) {
        courseService.addCourse(course);
        return Result.success("课程添加成功");
    }

    /**
     * 删除教师所授课程
     * @param courseId 课程id
     */
    @Operation(summary = "删除教师所授课程")
    @DeleteMapping("/deleteCourse/{courseId}")
    public Result<String> deleteCourse(@PathVariable Long courseId) {
        courseService.removeById(courseId);
        return Result.success("课程删除成功");
    }

    @Operation(summary = "修改教师所授课程")
    @PostMapping("/updateCourse")
    public Result<String> updateCourse(@RequestBody Course course) {
        courseService.updateCourse(course);
        return Result.success("课程修改成功");
    }

    @Operation(summary = "查询所有教师所授课程")
    @GetMapping("/getAllCourses")
    public Result<List<CourseVO>> getAllCourses() {
        return Result.success(courseService.getAllCourses());
    }

}
